package com.schoolai.schoolstudy.controller;

import com.schoolai.entity.SchoolSetNews;
import com.schoolai.entity.SchoolStudyEnglishWorkTaskList;
import com.schoolai.schoolstudy.req.SchoolStudyEnglishWorkTaskListREQ;
import com.schoolai.schoolstudy.service.SchoolStudyEnglishWorkTaskListService;
import com.schoolai.util.base.BaseRequest;
import com.schoolai.util.base.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bobby
 * @since 2025-09-29
 */
@RestController
@RequestMapping("/EnglishWorkTaskList")
@Slf4j
@Tag(name = "任务单词列表", description = "任务单词列表操作")
public class SchoolStudyEnglishWorkTaskListController {
    @Autowired
    SchoolStudyEnglishWorkTaskListService schoolStudyEnglishWorkTaskListService;
    @Operation(summary = "查询任务单词")
    @PostMapping("/search")
    Result search(@RequestBody SchoolStudyEnglishWorkTaskListREQ req) {
        return Result.ok(schoolStudyEnglishWorkTaskListService.queryPage(req));
    }
    @Operation(summary = "通过id获取任务单词")
    @GetMapping("/{id}")
    @ApiResponses({
            @ApiResponse(responseCode = "20000", description = "操作成功"),
            @ApiResponse(responseCode = "999", description = "错误")
    })
    public Result view(@PathVariable("id") String id) {
        return Result.ok(schoolStudyEnglishWorkTaskListService.getById(id));
    }

    @Operation(summary = "新增任务单词")
    @PostMapping
    @ApiResponses({
            @ApiResponse(responseCode = "20000", description = "操作成功"),
            @ApiResponse(responseCode = "999", description = "错误")
    })
    public Result save(@RequestBody SchoolStudyEnglishWorkTaskList schoolStudyEnglishWorkTaskList){
        return Result.ok(schoolStudyEnglishWorkTaskListService.saveOrUpdate(schoolStudyEnglishWorkTaskList));
    }
    @Operation(summary = "修改任务单词")
    @PutMapping
    @ApiResponses({
            @ApiResponse(responseCode = "20000", description = "操作成功"),
            @ApiResponse(responseCode = "999", description = "错误")
    })
    public Result update(@RequestBody SchoolStudyEnglishWorkTaskList schoolStudyEnglishWorkTaskList){
        return Result.ok(schoolStudyEnglishWorkTaskListService.saveOrUpdate(schoolStudyEnglishWorkTaskList));
    }

    @Operation(summary = "通过id删除任务单词")
    @DeleteMapping("/{id}")
    @ApiResponses({
            @ApiResponse(responseCode = "20000", description = "操作成功"),
            @ApiResponse(responseCode = "999", description = "错误")
    })
    public Result delete(@PathVariable("id") String id) {
        return Result.ok(schoolStudyEnglishWorkTaskListService.removeById(id));
    }
}
